<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工管理</title>
<!-- 导入jquery核心类库 -->
<%@include file="../include/jqueryeasyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/jqext/jquery.form.js"></script>

 <script type="text/javascript">
$(function(){
	
	window.pcode = GetQueryString('pcode') ;
	
	initUploadWindow();
	
	$('#progress').hide();
	
});

function initUploadWindow(){
	//初始化销售员窗口
	$('#uploadWindow').window({
           title: '名单详情',
           width: 500,
           modal: true,
           shadow: true,
           closed: true,
           height: 300,
           resizable:true,
           
           
           
       });


}



function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}




	function doAdd(){
		$('#addFenchangWindow').form('clear');
		$('#addFenchangWindow *').trigger('blur');// 离焦
		$('#addFenchangWindow').window("open").window('setTitle', '添加分场');
		$("input[name='lMIDFenChang']").val('-1'); 
		if(window.pcode!=null){
			$('#lMIDContract').combobox('select', window.pcode);
			
		}
		
	}
	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#searchcontent').val();
	     queryParams.lMCom = searchcontent;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
    function doExport(){
    	$.messager.alert('提示', "正在完善中...",'info')
    }
	 function doSearch(){
		
		//获取查询参数
		//查询
		//刷新easyui 
		/* var searchcontent = $('#searchcontent').val();
		//alert(searchcontent)
		if(null!=searchcontent&&searchcontent!=''){
			
			reloadgrid();
		}else{
			$.messager.alert('消息','<br>请输入查询内容 ','info');
		} */			
		reloadgrid();
	}
	
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
        	
        	
			$("input[name='lMIndustry']").val(rowData.lMIndustry);
			$("input[name='sLoginName']").val(rowData.sLoginName);
			$("input[name='lMProvince']").val(rowData.lMProvince);
			$("input[name='lMCity']").val(rowData.lMCity);
			$("input[name='lMCounty']").val(rowData.lMCounty);
			$("input[name='lMCom']").val(rowData.lMCom);
			$("input[name='lMAddress']").val(rowData.lMAddress);
			$("input[name='lMName']").val(rowData.lMName);
			
			$("input[name='lMTel']").val(rowData.lMTel);
			$("input[name='lMFax']").val(rowData.lMFax);
			$("input[name='lMPhone']").val(rowData.lMPhone);
			$("input[name='lMWeixin']").val(rowData.lMWeixin);
			$("input[name='lMQQ']").val(rowData.lMQQ);
			$("input[name='lMeMail']").val(rowData.lMeMail);
		
			
			$("input[name='lMIDFenChang']").val(rowData.lMIDFenChang);
 			
	 		$('#lMIDContract').combobox('select', rowData.lMIDContract);

			// 弹出窗口
			  
			$("#addFenchangWindow").window('open').window('setTitle', '修改分场');
        } 
	}
	
	
	
	// 定义列
	var columns = [ [  {
		field : 'v_creatorName',
		title : '创建人',
		width : 110,	
		
	},{
		field : 'lMIDContract',
		title : '项目编号',
		width : 110,	
		
	}, {
		field : 'lMCom',
		title : '单位名称',
		width : 260,
		
	}, {
		field : 'lMName',
		title : '联系人',
		width : 90,
		
	},  {
		field : 'lMIndustry',
		title : '行业',
		width : 110,
		
	},  {
		field : 'lMProvince',
		title : '省',
		width : 60,
		
	},  {
		field : 'lMCity',
		title : '市',
		width : 60,
		
	}, {
		field : 'lMCounty',
		title : '县/区',
		width : 60,
		
	}, {
		field : 'lMAddress',
		title : '地址',
		width : 150,
		
	}, {
		field : 'lMTel',
		title : '联系电话',
		width : 90,
		
	}, {
		field : 'lMFax',
		title : '联系传真',
		width : 90,
		
	}, {
		field : 'lMPhone',
		title : '联系手机',
		width : 90,
		
	}, {
		field : 'lMWeixin',
		title : '联系微信',
		width : 90,
		
	}, {
		field : 'lMQQ',
		title : '联系QQ',
		width : 90,
		
	}, {
		field : 'lMeMail',
		title : '联系邮箱',
		width : 120,
		
	}, {
		field : 'lMIDFenChang',
		title : '操作',
		width : 200,
		
		formatter:formaterupload
	} ] ];
	
	function formaterupload(value,row,index){
		return "<a onclick=doupload("+index+") href=#>上传花名册</a>&nbsp;&nbsp;&nbsp;&nbsp;"+
		"<a onclick=doshowhuamingce("+index+") href=#>查看花名册</a>&nbsp;&nbsp;&nbsp;&nbsp;"+
		"<a onclick=doDel("+index+") href=#>删除</a>";
	}
	
	function doDel(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    if(row){ 

		     $.messager.confirm("操作提示", "确认删除 当前分场？<br><br>删除此分场，将删除此分场下的所有花名册和测量数据,请谨慎操作.<br><br>删除后请在手机端搜索分场页面，重新选择分场，加载数据。", function (data) {  
		            if (data) {  
		            	$.post("${pageContext.request.contextPath}/linkman/page.delete.ashx?lMIDFenChang="+row.lMIDFenChang,function(data){
			    			
			    			if(data== "success"){
			    				// 成功
			    				$.messager.alert('消息','操作成功 ','info');
			    				reloadgrid();
			    				
			    			
			    			}else{
			    					$.messager.alert('消息','<br>操作失败','info');
			    				
			    			}
			    				
			    		}); 
		            }  
		            else {  
 		            }  
		        }); 


		}
	}
	
	function doupload(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	     

	    if(row){ 
	    	$('#uploadWindow').form('clear');
			$('#uploadWindow *').trigger('blur');// 离焦
			$('#uploadWindow').window("open").window('setTitle', "<"+row.lMCom+">"+'添加花名册');
 			$('#fenchangid').val(row.lMIDFenChang);
				
 		}
	}
	
	
	function doshowhuamingce(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	     

	    if(row){ 
	    	    var parent$ = self.parent.$;      //找到父级DOM  
	    	 
    	    	var text =row.lMCom+"花名册";
    	        var url="page.pcustomer.ashx?lMIDFenChang="+row.lMIDFenChang;
    			if (parent$("#tabs").tabs('exists', text)) {
    				parent$('#tabs').tabs('select', text);
    			} else {
    				var content = '<div style="width:100%;height:100%;overflow:hidden;">'
    						+ '<iframe src="'
    						+ url
    						+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

    					parent$('#tabs').tabs('add', {
    					title : text,
    					content : content,
    					closable : true
    				});
    			}
				
 			}
	}
	
	function formatterSex(value,row,index){
		if(row.sSex==1){
			return "男";
		}else if(row.sSex==0){
			return "女";
		}
	}
	
 
	
 
	$(function(){
		$('#add').click(doAdd);
		$('#edit').click(doEdit);
		$('#search').click(doSearch);
		$('#export').click(doExport);
		$('#downloadxls').click(doDownload);
	});
	
function doDownload(){	
		
	location.href="${pageContext.request.contextPath}/huamingce01.xls";
	}
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/linkman/page.list.ashx",
			idField : 'lMIDFenChang',
			columns : columns,
			pageList: [10,25,50],
			pagination:true,
			queryParams: window.pcode!=null?{ 'lMIDContract': window.pcode}:new Object(),
			  
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>",
			selectOnCheck: true,
			checkOnSelect: true
			
		});
		
		//初始化员工窗口
		$('#addFenchangWindow').window({
            title: '员工详情',
            width: 800,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:false
            
        });
		
	
		
		//提交表单
		$('#save').click(function(){
			
			
			var select = $('#lMIDContract').combobox('panel').find('.combobox-item-selected') 
			if(select.length==0){
				$.messager.alert('消息','请在下拉框中选取项目！','info');
				$('#lMIDContract').combobox('clear');
				return;
			}

				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
 
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/linkman/page.saveOrUpdateFenchang.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#addFenchangWindow').window('close');
							// 清除表单数据
							$("input[name='sId']").val('');
							$('#addFenchangWindow').form('clear');
							$('#addFenchangWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data=="conflict"){
							
							$.messager.alert('消息','分场名已经被占用 ','info');
							
						}else{
							$.messager.alert('消息','操作失败 ','info');
						}
							
					});
				}
				
			});	
		
		
	});
	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});
	$.extend($.fn.validatebox.defaults.rules, {   
	    //验证汉字   
	    CHS: {   
	        validator: function (value) {   
	            return /^[\u0391-\uFFE5]+$/.test(value);   
	        },   
	        message: '只能输入汉字'  
	    },   
	    //移动手机号码验证   
	    mobile: {//value值为文本框中的值   
	        validator: function (value) {   
	            var reg = /^1[3|4|5|7|8|9]\d{9}$/;   
	            return reg.test(value);   
	        },   
	        message: '输入手机号码格式不准确.'  
	    },   
	    //国内邮编验证   
	    zipcode: {   
	        validator: function (value) {   
	            var reg = /^[1-9]\d{5}$/;   
	            return reg.test(value);   
	        },   
	        message: '邮编必须是非0开始的6位数字.'  
	    },   
	    //用户账号验证(只能包括 _ 数字 字母)    
	    account: {//param的值为[]中值   
	        validator: function (value, param) {   
	            if (value.length < param[0] || value.length > param[1]) {   
	                $.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围';   
	                return false;   
	            } else {   
	                if (!/^[\w]+$/.test(value)) {   
	                    $.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.';   
	                    return false;   
	                } else {   
	                    return true;   
	                }   
	            }   
	        }, message: ''  
	    }   
	})
	
	
	
	

	
	           
		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	
	<div class="easyui-window" title="分场详情" id="addFenchangWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div>
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform" enctype='application/json'>
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="4">分场详情</td>
					</tr>

		
					<tr>
							<td>所属项目</td>
						<td>
						<input class="easyui-combobox"    
									required="true"
									name="lMIDContract"
									id="lMIDContract"
									data-options="
											  filter: function(q, row){  
													        var opts = $(this).combobox('options');  
													        return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配  
													    },
											url:'${pageContext.request.contextPath}/contract/page.list_all.ashx?refreshcache=new Date().getTime()',
											method:'post',
											valueField:'cPIDSerial',
											textField:'cPName',
											panelHeight:'300',
											panelWidth:'300'
						"></td>
											<td>分场名称</td>
						<td><input name="lMCom" id="lMCom" type="text" class="easyui-validatebox"  required="true"  /></td>

					</tr>
					<input id="lMIDFenChang" name="lMIDFenChang" type="hidden" class="easyui-validatebox"/>
					<tr>
						<td>省/直辖市</td>
						<td><input name="lMProvince" type="text" class="easyui-validatebox"  /></td>
						
					
						<td>市</td>
						<td><input name="lMCity" type="text" class="easyui-validatebox"   /></td>
					</tr>
					
					<tr>
						<td>县/区</td>
						<td><input name="lMCounty" type="text" class="easyui-validatebox"    /></td>
					

						<td>行&nbsp;&nbsp;&nbsp;&nbsp;业</td>
						<td>
						<input name="lMIndustry" type="text" class="easyui-validatebox"  /></td>
					</tr>

	
	
					<tr>
						<td>地&nbsp;&nbsp;&nbsp;&nbsp;址</td>
						<td><input name="lMAddress" type="text" class="easyui-validatebox"    /></td>
						
					
						<td>联系人</td>
						<td><input name="lMName" type="text" class="easyui-validatebox"    /></td>
					</tr>
					<tr>
					<td>手&nbsp;&nbsp;&nbsp;&nbsp;机</td>
						<td><input name="lMPhone" type="text" class="easyui-validatebox"    /></td>
						<td>座&nbsp;&nbsp;&nbsp;&nbsp;机</td>
						<td><input name="lMTel" type="text" class="easyui-validatebox"   /></td>
						
					
					
					</tr>
					
					<tr>
						
							<td>传&nbsp;&nbsp;&nbsp;&nbsp;真</td>
						<td><input name="lMFax" type="text" class="easyui-validatebox"   /></td>
					
						<td>微&nbsp;&nbsp;&nbsp;&nbsp;信</td>
						<td><input name="lMWeixin" type="text" class="easyui-validatebox"   /></td>
					</tr>
					<tr>
						<td>Q&nbsp;&nbsp;&nbsp;&nbsp;Q</td>
						<td><input name="lMQQ" type="text" class="easyui-validatebox"  /></td>
						
					
						<td>邮&nbsp;&nbsp;&nbsp;&nbsp;箱</td>
						<td><input name="lMeMail" type="text" class="easyui-validatebox"     /></td>
					</tr>
					
					</table>
			</form>
		</div>
	</div>
	
	
	<div  class="easyui-window" title="上传" id="uploadWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px;">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
		 <div class="datagrid-toolbar">
				<a id="saveHuamingce" onclick="uploadimg()" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div> 
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="fileform" enctype="multipart/form-data"accept="application/excel, application/vnd.ms-excel,application/x-excel, application/x-msexcel">
				<table class="table-edit" width="80%" align="center">
					
					
					
	            	    <tr>
		            	    <td>Excel文件</td> 
		            	    <td>
		            	    <input   accept="application/excel, application/vnd.ms-excel,application/x-excel, application/x-msexcel" id="file" type="file" name="huamingce"/>
		            	    <input id="fenchangid" name="fenchangid" type="hidden" value="">
		            	    </td>
	            	    </tr>
	            	    <tr><td colspan="2">*仅支持后缀为xls的Excel文件，点击"<a href="${pageContext.request.contextPath }/huamingce01.xls">下载花名册模板</a>"按钮可下载花名册模板</td></tr>
	            	    <tr><td colspan="2">*请勿修改模板表头。</td></tr>
	            	    <tr><td colspan="2">*输入或者粘贴数据时请不要设置格式，粘贴请选择仅粘贴值。</td></tr>
	            	    <tr><td colspan="2">*编号、姓名、性别、部门、单位为必填项。</td></tr>
					
					 
					
					</table>
			</form>
			
			<table  id="progress" class="table-edit"  width="80%" align="center">
					
					
					
	            	    <tr>
		            	    <td><img src="${pageContext.request.contextPath }/images/progress.jpg" alt="正在处理" width="42" height="42"></td> 
		            	    <td>正在处理，请稍等。。。</td>
	            	    </tr>
	            	   				 
					
					</table>
		</div>
	</div>
	
		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
			<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;单位名称: <input id="searchcontent" class="easyui-textbox" style="width:80px">
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#"  id="downloadxls" class="easyui-linkbutton" iconCls="icon-save">下载花名册模板</a>
			<!-- <a href="#"  id="export" class="easyui-linkbutton" iconCls="icon-redo">导出</a> -->
		
		</div>
	</div>
</body>

<script type="text/javascript">

/* 
var MaskUtil = (function(){
	
	var $mask,$maskMsg;
	
	var defMsg = '正在处理，请稍待。。。';
	
	function init(){
		if(!$mask){
			$mask = $("<div class=\"datagrid-mask mymask\"></div>").appendTo("body");
		}
		if(!$maskMsg){
			$maskMsg = $("<div class=\"datagrid-mask-msg mymask\">"+defMsg+"</div>")
				.appendTo("body").css({'font-size':'12px'});
		}
		
		$mask.css({width:"100%",height:$(document).height()});
		
		var scrollTop = $(document.body).scrollTop();
		
		$maskMsg.css({
			left:( $(document.body).outerWidth(true) - 190 ) / 2
			,top:( ($(window).height() - 45) / 2 ) + scrollTop
		}); 
				
	}
	
	return {
		mask:function(msg){
			init();
			$mask.show();
			$maskMsg.html(msg||defMsg).show();
		}
		,unmask:function(){
			$mask.hide();
			$maskMsg.hide();
		}
	}
	
}()); */

function uploadimg(){
	 
	//MaskUtil.mask();
	$('#fileform').hide();
	$('#progress').show();
	$('#saveHuamingce').hide();
	
 
	 $("#fileform").ajaxSubmit({   
	    	
	        type:"post",  //提交方式    
	        url:"${pageContext.request.contextPath}/customer/page.uploadHuaMingCe.ashx", //请求url 
	        success:function(data){ //提交成功的回调函数    
	        	
	        	
	        	if(data.status==1){
	        		//MaskUtil.unmask();
	        		//$('#saveHuamingce').show();
	        		  $('#fileform').show();
	    	$('#progress').hide();
	    	$('#saveHuamingce').show();
 	        		$('#grid').datagrid('reload');
	        		$.messager.alert("提示","上传成功！"); 
	        		$('#uploadWindow').window('close');
					// 清除表单数据
					$('#uploadWindow').form('clear');
					$('#uploadWindow *').trigger('blur');// 离焦
					$('#uploadWindow').window('close')
	        	}
	        if(data.status==0){
	        	//MaskUtil.unmask();
 	        	  $('#fileform').show();
	    	$('#progress').hide();
	    	$('#saveHuamingce').show();
 	        		
	        		$.messager.alert("提示",data.msg);  
	        		var file = $("#file");  
	        		file.after(file.clone().val(""));  
	        		file.remove(); 
	        	}
	        
	      
	        	
	        
	        },dataType:'json'    
	    });
}
</script>
</html>